{% extends "base/base.html" %}
{% block css %} 
<link rel="stylesheet" href="/static/css/login.css">
{% endblock %}
{% block content %}
<div class="form-box">
	<form id="logForm">
		<h2 class="f-title">{{ title }}</h2>
		<div class="f-item">
			<input type="text" name="username" placeholder="请输入账号">
		</div>
		<div class="f-item">
			<input type="password" name = "password" placeholder="请输入密码">
		</div>
		<div class="f-item1 tip">
			<span>没有账号?<a href="/register">点我注册</a></span>
			<span><a href="/forget">忘记密码</a></span>
		</div>
		<div class="f-item f-btn">
			<!-- <input class="btn" type="submit" value="点此登录"> -->
			<a class="btn" id="logBtn">点此登录</a>
		</div>
	</form>
</div>
{% endblock %}

{%block script%}
<script>
	let $logForm=$("#logForm"),$logBtn=$("#logBtn")
	// 按钮点击后的结果
	$logBtn.on('click',()=>{
		let formData = $logForm.serializeArray()
		let data = {}
		formData.map(item=>{
			data[item.name]=item.value
		})
		console.log(data);
		//??? 判断数据是否合法
		// 上传代码
		$.post('/api/login',data,res=>{
			res = JSON.parse(res)
			console.log(res)
			alert(res.msg)
			if(res.code == 200){
				//如果登录成功，则跳转到首页
				location.href="/"
			}
		})
		
	})
</script>
{% endblock %}